from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-20 14:02:15.372342
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 20, Mar, 2022
Time: 14:02:20
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.5919
Nobs: 600.000 HQIC: -48.9947
Log likelihood: 7203.18 FPE: 4.07722e-22
AIC: -49.2515 Det(Omega_mle): 3.51364e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349978 0.066721 5.245 0.000
L1.Burgenland 0.108182 0.040630 2.663 0.008
L1.Kärnten -0.110603 0.021244 -5.206 0.000
L1.Niederösterreich 0.193584 0.084919 2.280 0.023
L1.Oberösterreich 0.120984 0.083725 1.445 0.148
L1.Salzburg 0.258466 0.043091 5.998 0.000
L1.Steiermark 0.036712 0.056885 0.645 0.519
L1.Tirol 0.102556 0.045900 2.234 0.025
L1.Vorarlberg -0.067627 0.040521 -1.669 0.095
L1.Wien 0.015018 0.074524 0.202 0.840
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054619 0.143386 0.381 0.703
L1.Burgenland -0.037945 0.087315 -0.435 0.664
L1.Kärnten 0.041957 0.045655 0.919 0.358
L1.Niederösterreich -0.203464 0.182495 -1.115 0.265
L1.Oberösterreich 0.454730 0.179928 2.527 0.011
L1.Salzburg 0.282926 0.092606 3.055 0.002
L1.Steiermark 0.112715 0.122250 0.922 0.357
L1.Tirol 0.306193 0.098641 3.104 0.002
L1.Vorarlberg 0.026589 0.087081 0.305 0.760
L1.Wien -0.029418 0.160156 -0.184 0.854
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198500 0.034097 5.822 0.000
L1.Burgenland 0.089246 0.020764 4.298 0.000
L1.Kärnten -0.007181 0.010857 -0.661 0.508
L1.Niederösterreich 0.242201 0.043397 5.581 0.000
L1.Oberösterreich 0.159650 0.042787 3.731 0.000
L1.Salzburg 0.039900 0.022022 1.812 0.070
L1.Steiermark 0.027006 0.029071 0.929 0.353
L1.Tirol 0.081926 0.023457 3.493 0.000
L1.Vorarlberg 0.054185 0.020708 2.617 0.009
L1.Wien 0.116711 0.038085 3.064 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118666 0.034094 3.481 0.001
L1.Burgenland 0.043133 0.020762 2.078 0.038
L1.Kärnten -0.012912 0.010856 -1.189 0.234
L1.Niederösterreich 0.171821 0.043393 3.960 0.000
L1.Oberösterreich 0.335728 0.042783 7.847 0.000
L1.Salzburg 0.099753 0.022020 4.530 0.000
L1.Steiermark 0.111872 0.029068 3.849 0.000
L1.Tirol 0.089155 0.023455 3.801 0.000
L1.Vorarlberg 0.060706 0.020706 2.932 0.003
L1.Wien -0.018119 0.038082 -0.476 0.634
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126670 0.063985 1.980 0.048
L1.Burgenland -0.045114 0.038964 -1.158 0.247
L1.Kärnten -0.045289 0.020373 -2.223 0.026
L1.Niederösterreich 0.136789 0.081437 1.680 0.093
L1.Oberösterreich 0.159150 0.080292 1.982 0.047
L1.Salzburg 0.284786 0.041325 6.891 0.000
L1.Steiermark 0.058338 0.054553 1.069 0.285
L1.Tirol 0.158462 0.044018 3.600 0.000
L1.Vorarlberg 0.097737 0.038859 2.515 0.012
L1.Wien 0.071535 0.071468 1.001 0.317
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.077271 0.049923 1.548 0.122
L1.Burgenland 0.025906 0.030401 0.852 0.394
L1.Kärnten 0.053261 0.015896 3.351 0.001
L1.Niederösterreich 0.190663 0.063539 3.001 0.003
L1.Oberösterreich 0.330522 0.062646 5.276 0.000
L1.Salzburg 0.034763 0.032243 1.078 0.281
L1.Steiermark 0.008203 0.042564 0.193 0.847
L1.Tirol 0.119258 0.034344 3.472 0.001
L1.Vorarlberg 0.065876 0.030319 2.173 0.030
L1.Wien 0.096298 0.055762 1.727 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174963 0.060214 2.906 0.004
L1.Burgenland 0.005480 0.036668 0.149 0.881
L1.Kärnten -0.065900 0.019173 -3.437 0.001
L1.Niederösterreich -0.107303 0.076638 -1.400 0.161
L1.Oberösterreich 0.205915 0.075560 2.725 0.006
L1.Salzburg 0.054654 0.038889 1.405 0.160
L1.Steiermark 0.247030 0.051338 4.812 0.000
L1.Tirol 0.501651 0.041424 12.110 0.000
L1.Vorarlberg 0.064282 0.036569 1.758 0.079
L1.Wien -0.077848 0.067257 -1.157 0.247
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161109 0.066812 2.411 0.016
L1.Burgenland -0.001681 0.040685 -0.041 0.967
L1.Kärnten 0.062846 0.021273 2.954 0.003
L1.Niederösterreich 0.168026 0.085035 1.976 0.048
L1.Oberösterreich -0.057552 0.083839 -0.686 0.492
L1.Salzburg 0.208201 0.043150 4.825 0.000
L1.Steiermark 0.138731 0.056963 2.435 0.015
L1.Tirol 0.056789 0.045962 1.236 0.217
L1.Vorarlberg 0.147067 0.040576 3.624 0.000
L1.Wien 0.119560 0.074626 1.602 0.109
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.389999 0.039320 9.919 0.000
L1.Burgenland -0.003584 0.023944 -0.150 0.881
L1.Kärnten -0.020859 0.012520 -1.666 0.096
L1.Niederösterreich 0.202484 0.050044 4.046 0.000
L1.Oberösterreich 0.229963 0.049341 4.661 0.000
L1.Salzburg 0.036621 0.025395 1.442 0.149
L1.Steiermark -0.015635 0.033524 -0.466 0.641
L1.Tirol 0.088973 0.027050 3.289 0.001
L1.Vorarlberg 0.050955 0.023880 2.134 0.033
L1.Wien 0.044112 0.043919 1.004 0.315
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036586 0.104091 0.168130 0.138252 0.096979 0.080111 0.032655 0.208590
Kärnten 0.036586 1.000000 -0.026958 0.131052 0.048740 0.084776 0.443745 -0.066881 0.089266
Niederösterreich 0.104091 -0.026958 1.000000 0.312523 0.119291 0.272435 0.066574 0.153286 0.292046
Oberösterreich 0.168130 0.131052 0.312523 1.000000 0.212817 0.294901 0.166132 0.136451 0.238778
Salzburg 0.138252 0.048740 0.119291 0.212817 1.000000 0.122709 0.091765 0.105158 0.123948
Steiermark 0.096979 0.084776 0.272435 0.294901 0.122709 1.000000 0.133678 0.106883 0.035301
Tirol 0.080111 0.443745 0.066574 0.166132 0.091765 0.133678 1.000000 0.064070 0.150447
Vorarlberg 0.032655 -0.066881 0.153286 0.136451 0.105158 0.106883 0.064070 1.000000 -0.004209
Wien 0.208590 0.089266 0.292046 0.238778 0.123948 0.035301 0.150447 -0.004209 1.000000